<template>
  <div class="nav-header">
    <!-- <el-icon class="el-icon el-icon-s-fold" @click="handleFoldClick"> </el-icon> -->
    <div>
      <component
        :is="isFold ? 'Expand' : 'Fold'"
        class="el-icon el-icon-s-fold"
        @click="handleFoldClick"
      ></component>
    </div>
    <div class="content">
      <HyBreadcrumb :breadcrumbs="breadcrumbs" />
      <UserInfo />
    </div>
  </div>
</template>

<script lang="ts">
import { Expand, Fold } from '@element-plus/icons-vue'
import { defineComponent, ref, computed } from 'vue'
import UserInfo from './user-info.vue'
import HyBreadcrumb from '@/base-ui/breadcrumb'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'
import { pathMapBreadcrumbs } from '@/utlis/map-menus'

export default defineComponent({
  components: { UserInfo, HyBreadcrumb },
  emits: ['foldChange'],
  setup(props, { emit }) {
    const isFold = ref(false)
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }

    // 面包屑的数据:[{name:'',path:''}]
    const store = useStore()
    // const userMenus = store.state.login.userMenus
    // const route = useRoute()
    const breadcrumbs = computed(() => {
      const userMenus = store.state.login.userMenus
      const route = useRoute()
      const currentPath = route.path

      return pathMapBreadcrumbs(userMenus, currentPath)
    })

    return { isFold, handleFoldClick, Expand, Fold, breadcrumbs }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  align-items: center;
  width: 100%;
  .el-icon-s-fold {
    font-size: 30px;
    cursor: pointer;
  }

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
